import pymysql
class DBTool(object):
    @staticmethod
    def __sql_connect():
        conn = pymysql.connect(host="211.103.136.244", port=7061, user="student",
                               password="iHRM_student_2022", database="ihrm", charset="utf8")
        return conn

    @staticmethod
    def method_fetch(sql):
        conn = None
        curs = None
        result = None
        try:
            conn = DBTool.__sql_connect()
            curs = conn.cursor()
            curs.execute(sql)
            result = curs.fetchone()
        except Exception as error:
            print("出现的错误：", error)
        finally:
            curs.close()
            conn.close()
            return result

    @staticmethod
    def method_idu(sql):
        conn = None
        curs = None
        result1 = None
        try:
            conn = DBTool.__sql_connect()
            curs = conn.cursor()
            result1 = curs.execute(sql)
            conn.commit()
        except Exception as error:
            conn.rollback()
            print("出现的错误：", error)
        finally:
            curs.close()
            conn.close()
            return result1


if __name__ == '__main__':
    # print(resu1)
    DBTool.method_idu("update bs_user set username = '西西' where mobile = '13900047643 ';")
